import { createRouter, createWebHistory } from "vue-router";

//all routes
const appAllRoutes = [];
// function importAllRoutes(r) {
//   for (let key in r) {
//     appAllRoutes.push(...r[key].default);
//   }
// }
// importAllRoutes(import.meta.glob("./modules/*.js", { eager: true }));

const routes = [
  ...appAllRoutes,
  // 会员
  {
    path:'/member/index',
    component:()=>import('@/views/member/Index.vue'),
    name:'MemberIndex',
    meta:{
      title:'会员中心'
    },
  },

  {
    path: "/:pathMatch(.*)",
    name: "error",
    component: () => import("@/views/404.vue"),
    meta: { title: "404" },
  },
];

const router = createRouter({
  history: createWebHistory(import.meta.env.VITE_APP_BASE_URL),
  routes,
});

router.beforeEach(async (to, from, next) => {
  if(to.query.token){
    localStorage.setItem('token',to.query.token)
  }
  document.title = to.meta.title;
  next();
});

export default router;
